package com.lightsh.network;

public class NetworkProxy {
	
	private static final String KEY_NETWORK_CMWAP = "CMWAP";
	private static final String CMWAP_HOST = "10.0.0.172";
	private static final int CMWAP_PORT = 80;	
	public static final NetworkProxy CMWAP_PROXY = new NetworkProxy(CMWAP_HOST, CMWAP_PORT);
	
	private static NetworkProxy sProxyInfo = null;
	
	
	private String mProxyHost = null;
    private int mProxyPort = 0;
    
    public static final void updateProxyStatus(String extraInfo){
		if(isNetworkCMWap(extraInfo)){
			NetworkProxy.sProxyInfo = CMWAP_PROXY;
		}else{
			NetworkProxy.sProxyInfo = null;
		}
	}
    public static boolean isProxyEnable(){
    	return sProxyInfo != null && sProxyInfo.isProxyAvailable();
    }
    public static String getProxyHost(){
    	return isProxyEnable() ? sProxyInfo.getHost() : null;
    }
    public static int getProxyPort(){
    	return isProxyEnable() ? sProxyInfo.getPort() : 0;
    }
    
	private NetworkProxy(String proxyHost, int proxyPort){
		mProxyHost = proxyHost;
		mProxyPort = proxyPort;
	}
	
	private static final boolean isNetworkCMWap(String extraInfo){
		if(extraInfo != null && extraInfo.toUpperCase().contains(KEY_NETWORK_CMWAP)){
			return true;
		}else{
			return false;
		}
	}
	
	private String getHost(){
		return mProxyHost;
	}
	private int getPort(){
		return mProxyPort;
	}
	
	private boolean isProxyAvailable(){
		return mProxyHost != null && mProxyHost.length() > 0;
	}
}
